from ipaddress import IPv4Address

from common import OperatingSystem

from .agent_binary_request import AgentBinaryDownloadTicket, AgentBinaryTransform, ReservationID
from .http_agent_binary_server import HTTPAgentBinaryServer
from .i_http_agent_binary_server_registrar import IHTTPAgentBinaryServerRegistrar


class HTTPAgentBinaryServerRegistrar(IHTTPAgentBinaryServerRegistrar):
    def __init__(self, server: HTTPAgentBinaryServer):
        self._server = server

    def reserve_download(
        self,
        operating_system: OperatingSystem,
        requestor_ip: IPv4Address,
        agent_binary_transform: AgentBinaryTransform,
    ) -> AgentBinaryDownloadTicket:
        return self._server.register(operating_system, requestor_ip, agent_binary_transform)

    def clear_reservation(self, reservation_id: ReservationID):
        self._server.deregister(reservation_id)
